package com.app.oasystem.controller;


import com.app.oasystem.dto.ActionResult;
import com.app.oasystem.dto.PageGridDto;
import com.app.oasystem.dto.TableDto;
import com.app.oasystem.entity.User;
import com.app.oasystem.service.impl.UserServiceImpl;
import com.app.oasystem.vo.UserVo;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 86+
 * @data 2021-04-13
 */

@RestController
@RequestMapping(path = "/user")
public class UserController {

    @Resource
    UserServiceImpl userService;

    /**
     * 获取用户列表 getUserList
     */
    @PostMapping("/all")
    public TableDto getUserList(@RequestBody PageGridDto pageGridDto) {
        return userService.getUserList(pageGridDto);
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/{id}")
    public ActionResult getUserInfo(@PathVariable("id") Integer id) {

        return new ActionResult(userService.getUserInfo(id));
    }

    /**
     * 获取管理用户信息
     */
    @GetMapping("/admin")
    public ActionResult getAdminList() {
        return new ActionResult(userService.getAdminList());
    }

    @PostMapping("/add")
    public ActionResult insert(@RequestBody User user) {
        int update = userService.insert(user);
        return new ActionResult(update);
    }

    @PostMapping("/update")
    public ActionResult update(@RequestBody User user) {
        int update = userService.update(user);
        return new ActionResult(update);
    }

    @DeleteMapping("/{id}")
    public ActionResult delUser(@PathVariable("id") Integer id) {
        int update = userService.delUser(id);
        return new ActionResult(update);
    }
}

